package com.rdc.qingkou.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import com.githang.statusbar.StatusBarCompat;
import com.rdc.qingkou.Application.MyApplication;
import com.rdc.qingkou.R;

public class ReportActivity extends AppCompatActivity {

    private CheckBox mCheckBox_one;
    private CheckBox mCheckBox_two;
    private CheckBox mCheckBox_three;
    private CheckBox mCheckBox_four;
    private Button mReport;
    private ImageButton mBack;
    private EditText mDetails;
    private String text = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyApplication.addActivity(this);
        StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.windowBackground), true);
        setContentView(R.layout.activity_report);
        initViews();
        initEvents();
    }

    private void initViews() {
        mCheckBox_one = (CheckBox) findViewById(R.id.report_checkbox_one);
        mCheckBox_two = (CheckBox) findViewById(R.id.report_checkbox_two);
        mCheckBox_three = (CheckBox) findViewById(R.id.report_checkbox_three);
        mCheckBox_four = (CheckBox) findViewById(R.id.report_checkbox_four);
        mReport = (Button) findViewById(R.id.report_send_imageButton);
        mBack = (ImageButton) findViewById(R.id.title_back_imageButton);
        mDetails = (EditText) findViewById(R.id.report_content_editText);

    }

    private void initEvents() {
        mReport.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                check();
                String content = "";
                if (!TextUtils.isEmpty(mDetails.getText())) {
                    content = mDetails.getText().toString();
                }
                Toast.makeText(ReportActivity.this, text + content, Toast.LENGTH_SHORT).show();
            }
        });
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
    }

    /**
     * 检测选中条目并取得相应的值
     */
    private void check() {
        if (mCheckBox_one.isChecked()) {
            text += mCheckBox_one.getText().toString();
        }
        if (mCheckBox_two.isChecked()) {
            text += mCheckBox_two.getText().toString();
        }
        if (mCheckBox_three.isChecked()) {
            text += mCheckBox_three.getText().toString();
        }
        if (mCheckBox_four.isChecked()) {
            text += mCheckBox_four.getText().toString();
        }
    }
}
